/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package webprocessors;

import containers.TestScores;
import java.io.IOException;
import java.util.LinkedList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import readers.QueryStringHandler;
import readers.UserReader;

/**
 *
 * @author Chris
 */
public class webprocessorTestWords extends webprocessor {
    public webprocessorTestWords() {}
    
    @Override
    public String process(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        QueryStringHandler QSH = new QueryStringHandler(request.getQueryString());
        
        String tid = getUserName(request);
        String groupid = QSH.getElement("grpid");
        String testid = QSH.getElement("testid");
        LinkedList<String> words = new LinkedList<String>();
        
        if(tid == null || groupid == null || testid == null) {
            return "An error has occured";
        }

        if(!UserReader.getTest(tid, groupid, testid, words)) {
            return "No words are present, add words below";
        }
        
        String word;
        String output = "<table><tr><td>Words in test</td></tr>";  
        while(!words.isEmpty()) {
            word = words.removeFirst();
            output += "<tr><td>" + word + "</td></tr>";
        }
        
        output += "</table>";
        
        return output;
    }

}
